<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <?php
        include '../admin/Config.php';
        // insert into database
        $idChinhSua = 0;
        $i = 0;
        $tenBaiViet = '';
        $gioiThieu = '';
        $ngayTao = null;
        $ngaySua = null;
        if (isset($_GET['id'])) {
            $idChinhSua = $_GET['id'];
        }
        if ($idChinhSua > 0 && isset($_GET['flag'])) {
            $tenBaiViet = $_GET['tenBaiViet'];
            $gioiThieu = $_GET['gioiThieu'];
            $queryChinhSuaBaiViet = "UPDATE BAIVIET set tenBaiViet = '$tenBaiViet', gioiThieu = '$gioiThieu' WHERE id = $idChinhSua";
            $resultBaiViet = mysql_query($queryChinhSuaBaiViet);
            mysql_affected_rows();
            echo 'Chỉnh sửa thành công!';
        }
        if ($idChinhSua > 0) {
            $queryChinhSuaBaiViet = "Select * from BAIVIET WHERE id = $idChinhSua";
            $resultBaiViet = mysql_query($queryChinhSuaBaiViet);
            $numrowBaiViet = mysql_num_rows($resultBaiViet);
            if ($numrowBaiViet > 0) {
                $id = mysql_result($resultBaiViet, 0, 'id');
                $tenBaiViet = mysql_result($resultBaiViet, 0, 'tenBaiViet');
                $gioiThieu = mysql_result($resultBaiViet, 0, 'gioiThieu');
                $ngayTao = mysql_result($resultBaiViet, 0, 'ngayTao');
                $ngaySua = mysql_result($resultBaiViet, 0, 'ngaySua');
            }
        }
        ?>

        <div>
            <form action="baiViet_chinhSua.php" method="get">
                <?php echo $idChinhSua; ?>
                <input type="hidden" name="flag" value="1" />
                <input type="hidden" name="id" value="<?php echo $idChinhSua; ?>"/>
                <table>
                    <tr>
                        <td>
                            Tên  bài viết
                        </td>
                        <td>
                            <input name="tenBaiViet" type="text" value="<?php echo $tenBaiViet; ?>"/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Giới thiệu
                        </td>
                        <td>
                            <textarea name="gioiThieu" rows="10" cols="100">
                                <?php echo $gioiThieu; ?>
                            </textarea>
                        </td>
                    </tr>
                </table>
                <input type="submit" value="Ghi nhận" />
            </form>
            <a href="index.php" >Danh sách</a>
        </div>
    </body>
</html>
